package io;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;

public class PWDemo2 {
    public static void main(String[] args) throws FileNotFoundException {
        //文件流（字节流，低级流）
        FileOutputStream fos = new FileOutputStream("pw.txt");
        //转换流（字符流，高级流）
        OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8);
        //字符缓冲流（字符流，高级流）
        BufferedWriter bw = new BufferedWriter(osw);
        //PrintWriter（字符流，高级流）
        PrintWriter pw = new PrintWriter(bw,true);

        Scanner scanner = new Scanner(System.in);
        while(true){
            System.out.print("请输入存入内容，输入exit退出：");
            String line = scanner.nextLine();
            if ("exit".equals(line)){
                System.out.println("退出");
                break;
            }
            pw.println(line);
        }
        pw.close();
    }
}
